const { ipcRenderer } = require("electron");
const { readFile } = require('fs/promises')
const buffer = require("node:buffer")
const path = require('path')
window.ipcRenderer = ipcRenderer;
window.readFile = readFile;
window.buffer = buffer;
window.path = path;

window.conterSetting = {
  width: 280,
  height: 550,
  conter: false
}

// index.html
window.alwaysOnTop = () => {
  ipcRenderer.sendTo(window.senderId, "win", "alwaysOnTop");
  let data = window.getData()
  window.sendSaveData(data)
};

window.isAlwaysOnTop = () => {
  ipcRenderer.sendTo(window.senderId, "win", "isAlwaysOnTop");
};

window.getPosition = () => {
  ipcRenderer.sendTo(window.senderId, "win", "position");
};

window.moveDirection = (type, num) => {
  ipcRenderer.sendTo(window.senderId, "direction", {type, num});
}

window.sendSaveData = (data) => {
  ipcRenderer.sendTo(window.senderId, "saveData", data);
};

ipcRenderer.on("senderId", (event) => {
  window.senderId = event.senderId;
});

window.closeWin = () => {
  if(window.removeBaseImg){
    let data = window.getData();
    if(data.list && data.list.length){
      data.list.forEach(item=>{
        window.removeBaseImg(item.urls)
      })
    }
  }
  if(window.closeSettingWin){
    window.closeSettingWin();
  }
  if(window.closePopupWin){
    window.closePopupWin();
  }
  ipcRenderer.sendTo(window.senderId, "win", "close");
};

// 向父页面传送数据
window.toParentPage = (data, info) => {
  ipcRenderer.sendTo(window.senderId, 'toParent', {data, ...info});
}
